#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include"Student.h"
using namespace std;

int main()
{
    string str;
    int score;
    vector<Student> students;
    int i=0,j=0;
    int q1=0,q2=0,q3=0,q4=0,q5=0;
    int sum=0,sum1=0,sum2=0,sum3=0,sum4=0,sum5=0;
    int max1=-1,max2=-1,max3=-1,max4=-1,max5=-1;
    int min1=10000,min2=10000,min3=10000,min4=10000,min5=10000;
    float av1,av2,av3,av4,av5;

    ifstream input("input.txt");

    Student student;
    student.no= ++i;
    j=0,sum=0;
    input >> student.name;
    
    while (input >> str)
    {
        if(str == "subjectA")
        {
            input >> student.score1;
            sum += student.score1;
            j++;q1++;
            sum1 += student.score1;               
            if(max1<student.score1){max1=student.score1;}
            if(min1>student.score1){min1=student.score1;}
        }
        else if(str == "subjectB")
        {
            input >> student.score2;
            sum += student.score2;
            j++;q2++;
            sum2 += student.score2;
            if(max2<student.score2){max2=student.score2;}
            if(min2>student.score2){min2=student.score2;}
        }
        else if(str == "subjectC")
        {
            input >> student.score3;
            sum += student.score3;
            j++;q3++;
            sum3 += student.score3;
            if(max3<student.score3){max3=student.score3;}
            if(min3>student.score3){min3=student.score3;}
        }
        else if(str == "subjectD")
        {
            input >> student.score4;
            sum += student.score4;
            j++;q4++;
            sum4 += student.score4;
            if(max4<student.score4){max4=student.score4;}
            if(min4>student.score4){min4=student.score4;}
        }
        else if(str == "subjectE")
        {
            input >> student.score5;
            sum += student.score5;
            j++;q5++;
            sum5 += student.score5;
            if(max5<student.score5){max5=student.score5;}
            if(min5>student.score5){min5=student.score5;}
        }
        else
        {
            student.average = (sum)/(j*1.0);
            students.push_back(student);
            student = Student();
            student.no= ++i;
            j=0,sum=0;
            student.name = str;
        }
    }
    student.average = (sum)/(j*1.0);
    students.push_back(student);

    av1=sum1/(q1*1.0);
    av2=sum2/(q2*1.0);
    av3=sum3/(q3*1.0);
    av4=sum4/(q4*1.0);
    av5=sum5/(q5*1.0);

    cout << "no\tname\tscore1\tscore2\tscore3\tscore4\tscore5\taverage\t"<< endl;
    for (const auto& student : students) {
        cout << student.no << "\t" << student.name << "\t" << student.score1 << "\t" << student.score2 << "\t" << student.score3 << "\t" << student.score4 << "\t" << student.score5 << "\t" << student.average << "\t" << endl;
    }
    cout << "\taverage" << "\t" << av1 << "\t" << av2 << "\t" << av3 << "\t" << av4 << "\t" << av5 << endl;
    cout << "\tmin" << "\t" << min1 << "\t" << min2 << "\t" << min3 << "\t" << min4 << "\t" << min5 << endl;
    cout << "\tmax" << "\t" << max1 << "\t" << max2 << "\t" << max3 << "\t" << max4 << "\t" << max5 << endl;
    return 0;
}
